/**
 * 医嘱操作界面的js
 */
var vbu09;//会员卡密码
var vbdList = [];//本次计价信息
var vajList = [];//本次费用记录
var totalVbi = 0.0;//本次总消费金额
var savePrintList=[];
var vajFlag = true;//查询费用是否成功的标识
var kucunsendFlag = true;//发送事库存校验
function checkALlAdvice()
{
	if ($("#checkedAll").prop("checked") == true)
	{
		$("input[name='advice']").each(function()
		{
			$(this).prop("checked", true);
		});
	}
	else
	{
		$("input[name='advice']").each(function()
		{
			$(this).prop("checked", false);
		});
	}
}
//var sendFlag = true;//控制发送流程(弹出诊金框)
// 发送医嘱
function sendAdvice()
{
	$("#fasong").attr("disabled",true);
	var isoperate = isOperateAdvice();
	if(!isoperate){
		layer.msg("该病人已经过了开嘱期限，请重新挂号！",{ time: 3000,icon: 0,skin: 'layui-layer-msg0'});
		return false;
	}
	if ($(".innerHead td input:checked").length <= 0)
	{
		layer.msg("请选择要发送的医嘱",
		{
		time : 2000,
		icon : 0,
		skin: 'layui-layer-msg0'
		});
		$("#fasong").removeAttr("disabled");
		return;
	}
	else
	{
		var flag = false;
		$(".innerHead td input:checked").each(function()
				{ // 遍历选中的checkbox
			$(this).parents("tbody").find(".yizhu_details").each(function(i, e)
					{
				var dataStr = $(e).attr("data-info");
				var dataObj = JSON.parse(dataStr);
				var vaf10 = dataObj.vaf10;
				if(vaf10!='1')
				{
					flag=true;
				}
					});
				});
		if(flag)
		{
			layer.alert("医嘱已发送或者已作废，不能再发送！",{icon:0,title:'提示'});
			$("#fasong").removeAttr("disabled");
			return;
		}
		layer.confirm('是否确定要发送？',  
		{
			btn : [
			'确定', '取消'
			],
			icon:3,
		// 按钮
		}, function()
		{
			/*
			 * 弹出选择诊金的框
			 */
			
			if (valueArr['p_9999_9999_104']=="1")
			{
				zhenjin1();
			}
			else
			{
				var zjAddList = [];
				sendZj(zjAddList);
			}
		}, function()
		{
			$("#fasong").removeAttr("disabled");
		});
	}

}

function sendZj(zjAddList)
{
	totalVbi = 0.0;
	var vbd1 = [];
	var vaf1 = [];
	var cbm01Arr = [];
	layer.msg('发送中....',
	{
	icon : 16,
	skin : 'layui-layer-msg16',
	shade : [
	0.1, '#393D49'
	],
	time : 0
	});
	var cbm01Arr_send = [];//生成计价信息用
	$(".innerHead td input:checked").each(function()
	{ // 遍历选中的checkbox
		$(this).parents("tbody").find(".yizhu_details").each(function(i, e)
		{
			var length1 = $(this).parents("tbody").find(".yizhu_details").length;
			var dataStr = $(e).attr("data-info");
			var dataObj = JSON.parse(dataStr);
			vaf1.push(dataObj);

			var vaf01 = dataObj.vaf01;
			var vaf10 = dataObj.vaf10;
			var bda01 = dataObj.bda01;
			var bby01 = dataObj.bby01;
			var bby25 = dataObj.bby25;
			var dsk01 = dataObj.dsk01;
			var bck01b = dataObj.bck01b;
			var cbm01 = dataObj.cbm01;
			cbm01Arr_send.push(cbm01);
			if ("LE".indexOf(bda01) >= 0)
			{
				var obj = {};
				obj.cbm01 = cbm01;
				obj.bda01 = bda01;
				cbm01Arr.push(obj);
			}
		});
	});
	cbm01Arr_send = cbm01Arr_send.unique2();//去重

	
	for (var i = 0; i < cbm01Arr_send.length; i++)
	{
		vbdInfoForsend_final(cbm01Arr_send[i]);
		for (var j = 0; j < vbdList.length; j++)
		{
			var vbdT = {};
			vbdT.vaf01 = vbdList[j]["vaf01"];
			vbdT.bby01 = vbdList[j]["bby01"];
			vbdT.vbd04 = vbdList[j]["vaf21"];// 数量
			vbdT.bby25 = vbdList[j]['bby25'];// 剂量单价
			totalVbi += parseFloat($("#bencidaijie").text());//遍历累加消费金额
			vbdT.vbd05 = vbdList[j]['lprice'];// 门诊包装单价
			vbdT.vbd06 = vbdList[j]['bdu06'];// 是否有从项
			vbdT.bck01 = vbdList[j]['bck01'];// 执行科室
			vbdT.bdn01 = vbdList[j]['bdn01'];// 医嘱项目类型
			vbdT.vbd08 = vbdList[j]['bdu07'];// 费用性质
			vbdT.vbd09 = vbdList[j]['bdu10'];// 收费方式
			vbdT.dsk01 = vbdList[j]['dsk01'];// 药品批次
			vbdT.bby01a = vbdList[j]['bby01a'];// 收费套餐ID
			vbdT.vbd12 = vbdList[j]['vbd12'];// 诊疗收费对照数量
			vbdT.bag23 = vbdList[j]['bag23'];// 诊疗收费对照数量
			vbdT.bag05 = vbdList[j]['bag05'];// 诊疗收费对照数量
			vbdT.bby05 = vbdList[j]['bby05'];// 诊疗收费对照数量
			vbd1.push(vbdT);
		}
	}
	if(!vajFlag && kucunsendFlag)
	{
		layer.alert("后台异常，请联系管理员",
				{
				icon : 2,
				});
		$("#fasong").removeAttr("disabled");
	}
    else if(kucunsendFlag)
	{
		var xmlObj = {};
		xmlObj.VAF1 = vaf1;
		xmlObj.VBD1 = vbd1;
		debugger;
		xmlObj.zjAddList = zjAddList;
		var xml = JSON.stringify(xmlObj);
		var vaa01 = $("#vaa01").val();
		var vac01 = $("#vac01").val();
		// 开始异步发送
		$.ajax(
		{
		url : rootUrl + "/clisendadvice/clinicadvicesend",
		data :
		{
		"lXml" : xml,
		"lSign" : 2,
		"lBCE01" : bce01,
		"lBCE02" : loginName,
		"lBCE03" : bce03,
		"lBCK01" : bck01,
		"lACF01" : 1,
		"lVAA07" : vac01,
		"lVAA01" : vaa01,
		},
		dataType : "json",
		method : "post",
		success : function(data)
		{
			//layer.close(index);
			if (data.result == "Success")
			{
				savePrintList = data.list;
				
				$("#fasong").removeAttr("disabled");
				debugger;
				// 返回医嘱查看界面
				reloadPatientInfo($("#vac01").val());
				//patientDoctorAdvice($("#vac01").val(), curr);
				// 开始更新医嘱抄送记录和生成诊疗申请单
				var url9 = rootUrl + "/clidoctor/nurse_Lis_Bills_Print_batch";
				var params9 = {};
				params9.bce03 = bce03;
				params9.cbm01Arr = JSON.stringify(cbm01Arr);
				var temp_vbq = {};
					temp_vbq.vbq27 = $(".e_jianchamudi").val();
					temp_vbq.vbq28 = $(".e_linchuangzhenduan").val();
					temp_vbq.vbq29 = $(".e_binglizhaiyao").val();
					temp_vbq.vbq30 = $(".e_fuzhujiancha").val();
				params9.vbq1 = JSON.stringify(temp_vbq);
				$.ajax(
				{
				async : false,
				url : url9,
				type : 'post',
				dataType : 'json',
				data : params9,
				success : function(data9)
				{
					layer.msg('发送成功',
							{
							time : 2000,
							icon : 1,
							skin : 'layui-layer-msg1'
							});
				}
				});

				// 如果是一卡通扣费用户，执行扣费操作
				var vipId = $("#vipId").text();
				if (false)
//				if (valueArr['p_9999_9999_112']=='1' && vipId != "--")
				{
					var msg = "";
					if ($("#vbu14").text() * 1 < totalVbi)
					{
						msg = "卡内基本余额：" + $("#vbu14").text() + "元；本次消费总额：" + totalVbi + "元。请先充值。。。";
						layer.alert(msg,
						{
						icon : 1,
						title : "温馨提示："
						});
						return true;
					}
					else
					{
						vbu09 = newCardOut(2);//弹出消费窗口
						vajList = data.rows;
					}
				}
				else
				{
					debugger
					var sobj = {};
					sobj.vac01 = $("#vac01").val()
					sobj.flag = true;
					sobj.list = savePrintList;
//					sobj.sql = getDiagnoseSql();
					if(data.commList&&data.commList.length>0){
						sobj.msg = feeTipMsg(data.commList);
						parent.closeAndPrint(sobj);
						
					}else{
						sobj.msg = false; 
						parent.closeAndPrint(sobj);
					}
//					if(data.commList&&data.commList.length>0){
//						closeAndPrint($("#vac01").val(),true,savePrintList,feeTipMsg(data.commList));
//					}else{
//						
//						closeAndPrint($("#vac01").val(),true,savePrintList,false);
//					}
					
				}
			}
			else
			{
				layer.alert(data.resultMsg,
				{
				icon : 2,
				});
				$("#fasong").removeAttr("disabled");
			}
		},error:function(a,b,c){
			console.log(c);
		}
		});
	}
	
}
function feeTipMsg(commList){
	commList = commList[0];
	var cardYe = parseFloat(commList.vbu14?commList.vbu14:0);
	var totalV = parseFloat(commList.vaj37?commList.vaj37:0);
	var cardr = totalV - cardYe;
	var msg;
	if(cardr>=0 ){
		msg = "本次待结费用："+totalV+"；<br>卡内基本余额：" + cardYe + "；<br><span style='color:red'>需补交:  "+cardr+"<span> 。";
	}else{
		msg = "本次待结费用："+totalV+"；<br>卡内基本余额：" + cardYe + "。";
		
	}
	return msg;
}
function tipCardMsg(commList){
	if(commList&&commList.length>0){
		var msg = feeTipMsg(commList);
		if (valueArr['p_100_105002_362']=='1' && vipId != "--")
		{
			layer.alert(msg,
					{
				icon : 1,
				title : "温馨提示："
					});
			return true;
			
		}
		
	}
}
/**
 * 点击额确认交易的事件
 */
function chareCardUpdate()
{
	$.ajax({
		url: rootUrl + "/clidoctor/getMD5PassWord",
		type: "GET",
		dataType: 'json',
		data: {password:vbu09},
		success:function(json){
			debugger;
		if(cardMap.vbu09 != json.pass)
		{
			layer.alert("密码错误，请重新输入");
		}
		else if(cardMap.vbu09 == json.pass)
		{
			debugger;
			layer.closeAll();
			for (var int = 0; int < vajList.length; int++)
			{
				var vaj = vajList[int];
				var params = {};
				params.VAA01 = vaj.vaa01;
				params.VAA07 = vaj.vaa07;
				params.VAI01 = vaj.vai01;
				params.ACF01 = vaj.acf01;
				params.BCE01 = vaj.bce03a;//操作员id
				params.BCK01 = vaj.bck01b;//科室id
				params.BCE02 = vaj.bce02b;//操作员code
				params.BCE02 = vaj.bce03a;//操作员姓名
				params.VAJ38 = vaj.vaj38;//基本账户扣费
				params.AType = 0;//0 = 扣费,1 = 退费
				params.AWorkType = 1;//门诊记账
				var postData = {};
				postData.chargejson = JSON.stringify(params);
				$.ajax
				({
					url:memberUrl+"/member/memberManger/horatecardchargeupdate",//调用rest
//					url:"http://192.168.1.156:8089/rateweb/cloud/member/memberManger/horatecardchargeupdate",
					type:"get",
					dataType:"jsonp",
					data:postData,
					success:function(data)
					{
						var vipId = $("#vipId").text();
						if(data && data.result.toLowerCase()=="success")
						{
							layer.closeAll();
							layer.msg("会员卡 "+vipId+" 已成功扣费"+totalVbi+"元",{icon:1,time:3000,skin: 'layui-layer-msg1'});
						}
						else 
						{
							layer.alert("会员卡 "+vipId+" 扣费失败，请联系管理员！",{icon:2,title:"警告"});
						}
					}
				});
			}
		}
	}});
}

// 发送前的查询--最终版本
function vbdInfoForsend_final(cbm01)
{
    debugger;
	var url = rootUrl + "/basicinformationquery/basequery";
	var params = {},data1 = {};
    params.sqlId = 2118;
    params.cbm01 = cbm01;
    data1.params = JSON.stringify(params);
	$.ajax(
	{
	url : url,
	type : "get",
	data : data1,
	async : false,
	dataType : 'json',
	success : function(data)
	{
		if(data.result=="Failure")
		{
			vajFlag = false;
		}
		else
		{
			vbdList = [];
			var msg = '';
            var bby01Arr_1 = [];
            var bby01Arr_11 = [];// 储存西、成药品需要数量和库存数量的json数组
            var bby01Arr_4 = [];
            var bby01Arr_41 = [];// 储存材料需要数量和库存数量的json数组
            vajFlag = true;
            var list = data.list;
            debugger;
			for (var i = 0; i < list.length; i++)
			{
				var temp = {};
				temp.bby01 = list[i].bby01;
				temp.vaf21 = list[i].vaf21;
				temp.bby05 = list[i].bby05;
				temp.zxks = list[i].bck01;
				vbdList.push(list[i]);
				if(!list[i].bck01)
				{
					kucunsendFlag = false;
                    layer.alert(list[i].bby05+"执行科室配置错误",
                        {
                            icon : 2
                        });
					return;
				}
				if("123".indexOf(list[i].bdn01)>=0)
				{
                    bby01Arr_11.push(temp);
                    bby01Arr_1.push(temp);
				}
				else if("4M".indexOf(list[i].bdn01)>=0)
				{
                    bby01Arr_41.push(temp);
                    bby01Arr_4.push(temp);
				}
			}

			//
            if (valueArr['p_9999_9999_106']=='1')
            {
                $.ajax(
                    {
                        url : rootUrl + "/doctoradviceeditor/checkdrugstoreNew_cailiao",
                        data :
                            {
                                bck01_c : valueArr['p_100_105002_404']=="-1"?bck01:valueArr['p_100_105002_404'],
                                lACF01 : 1,
                                bby01Arr_4 : JSON.stringify(bby01Arr_4)
                            },
                        dataType : "json",
                        type : "post",
                        async : false,
                        success : function(data)
                        {
                            debugger;
                            var list = data.list;
                            for (var i = 0; i < list.length; i++)
                            {
                                for (var j = 0; j < bby01Arr_41.length; j++)
                                {
                                    if (bby01Arr_41[j]["bby01"] == list[i]["bby01"])
                                    {
                                        bby01Arr_41[j].amount = list[i]["amount"];
                                    }
                                }
                            }
                            for (var i = 0; i < bby01Arr_41.length; i++)
                            {
                                if (!bby01Arr_41[i]["amount"])
                                {
                                    msg += bby01Arr_4[i]["bby05"] + "--需要数量为" + bby01Arr_41[i]["vaf21"] + ",当前库存数量为0;<br/>";
                                }
                                else if ((Number(bby01Arr_41[i]["amount"]) < Number(bby01Arr_41[i]["vaf21"])))
                                {
                                    console.log(bby01Arr_41[i]);
                                    msg += bby01Arr_41[i]["bby05"] + "--需要数量为" + bby01Arr_41[i]["vaf21"] + ",当前库存数量为" + bby01Arr_41[i]["amount"] + ";<br/>";
                                }
                            }
                            if ("" != msg)
                            {
                                kucunsendFlag = false;
                                layer.alert(msg,
                                    {
                                        title : '库存不足提示'
                                    });
                                $(thisbutton).removeAttr("disabled");
                            }
                        }
                    });
            }
            // 确认医嘱前检验药品库存是否足够
            var url = rootUrl + "/doctoradviceeditor/checkdrugstoreNew";
            var params = {bck01_x:valueArr['p_100_105002_108'],bck01_z:valueArr['p_100_105002_110']};
            params.lACF01 = 1;
            params.bby01Arr_1 = JSON.stringify(bby01Arr_1);

            $.ajax({url:url, data:params, type:"post",dataType:"json",async:false,success:function(data)
            {
                var list = data.list;
                for (var i = 0; i < list.length; i++)
                {
                    for (var j = 0; j < bby01Arr_11.length; j++)
                    {
                        if (bby01Arr_11[j]["bby01"] == list[i]["bby01"])
                        {
                            bby01Arr_11[j].amount = list[i]["amount"];
                        }
                    }
                }
                for (var i = 0; i < bby01Arr_11.length; i++)
                {
                    if (!bby01Arr_11[i]["amount"])
                    {
                        msg += bby01Arr_1[i]["bby05"] + "--需要数量为" + bby01Arr_11[i]["vaf21"] + ",当前库存数量为0;<br/>";
                    }
                    else if ((Number(bby01Arr_11[i]["amount"]) < Number(bby01Arr_11[i]["vaf21"])))
                    {
                        console.log(bby01Arr_11[i]);
                        msg += bby01Arr_11[i]["bby05"] + "--需要数量为" + bby01Arr_11[i]["vaf21"] + ",当前库存数量为" + bby01Arr_11[i]["amount"] + ";<br/>";
                    }
                }
                if ("" != msg)
                {
                    kucunsendFlag = false;
                    layer.alert(msg,
                        {
                            title : '库存不足提示'
                        });
                    $(thisbutton).removeAttr("disabled");
                }
            }});

		}
		
	}
	});
}

// 查询医嘱计价信息--send用
function vbdInfoForsend(vaf10, vaf01, bda01)
{
	var htmlContent = "";
	var url = "";
	var data1 = {};
	if (vaf10 == 1)
	{
		if (bda01 == "1" || bda01 == "2")// 844
		{
			url = rootUrl + "/advicevaluation/unSendAdviceXiyaoValuation";
			data1.lVAF01A = vaf01;
		}
		else if (bda01 == "3" || bda01 == "8")// 843
		{
			url = rootUrl + "/advicevaluation/unSendAdviceZhongyaoValuation";
			data1.lVAFID = vaf01;
		}
		else if (bda01 == "S")// 1031
		{
			url = rootUrl + "/advicevaluation/unsendadvicevaluation";
			data1.lVAFID = vaf01;
		}
		else
		// 1032
		{
			url = rootUrl + "/advicevaluation/otheradvicecharg";
			data1.lVAFID = vaf01;
		}
	}
	else if (vaf10 == 8)
	{
		if (bda01 == "1" || bda01 == "2")// 1035
		{
			url = rootUrl + "/advicevaluation/sendtempadvicevaluation";
			data1.lVAF01 = vaf01;
			data1.acf01 = "1";
			data1.lVAF01A = "";
		}
		else if (bda01 == "3" || bda01 == "8")// 1036
		{
			url = rootUrl + "/advicevaluation/sendedAdviceCaoyaoValuation";
			data1.lVAFID = vaf01;
		}
		else if (bda01 == "S")// 1037
		{
			url = rootUrl + "/advicevaluation/sendedadvicevaluation";
			data1.lVAFID = vaf01;
		}
		else
		// 1038
		{
			rootUrl + "/advicevaluation/sendotheradvice";
			data1.VAF01 = vaf01;
			data1.acf01 = "1";
		}
	}
	$.ajax(
	{
	url : url,
	type : "post",
	data : data1,
	async : false,
	dataType : 'json',
	success : function(data)
	{
		vbdList = data.list;
	}
	});
}
// 查询医嘱计价信息
function vbdInfo(dataobj)
{
	var vaf10 = dataobj.vaf10;
	var vaf01 = dataobj.vaf01;
	var bda01 = dataobj.bda01;
	var vaf01a = dataobj.vaf01a;
	var dl1 =$("#date1_p").val();
	var dl2 =$("#dl2").val();
	var htmlContent = "";
	var list;
	var url = "";
	var data1 = {};
	data1.date1=dl1;
	data1.date2=dl2;
	if (vaf10 == 1)
	{
		if (bda01 == "1" || bda01 == "2")// 844
		{
			url = rootUrl + "/advicevaluation/unSendAdviceXiyaoValuation";
			data1.lVAF01A = vaf01a;
		}
		else if (bda01 == "3" || bda01 == "8")// 843
		{
			url = rootUrl + "/advicevaluation/unSendAdviceZhongyaoValuation";
			data1.lVAFID = vaf01;
		}
		else if (bda01 == "S")// 1031
		{
			url = rootUrl + "/advicevaluation/unsendadvicevaluation";
			data1.lVAFID = vaf01;
		}
		else if(bda01 == "4" || bda01 == "M")
		{
			url = rootUrl + "/advicevaluation/unsendadvicevaluationCailiao";
			data1.lVAFID = vaf01;
		}
		else
		// 1032
		{
			url = rootUrl + "/advicevaluation/otheradvicecharg";
			data1.lVAFID = vaf01;
		}
	}
	else if (vaf10 == 8)
	{
		if (bda01 == "1" || bda01 == "2")// 1035
		{
			url = rootUrl + "/advicevaluation/sendtempadvicevaluation";
			data1.lVAF01 = vaf01;
			data1.acf01 = "1";
			data1.lVAF01A = vaf01a;
		}
		else if (bda01 == "3" || bda01 == "8")// 1036
		{
			url = rootUrl + "/advicevaluation/sendedAdviceCaoyaoValuation";
			data1.lVAFID = vaf01;
		}
		else if (bda01 == "S")// 1037
		{
			url = rootUrl + "/advicevaluation/sendedadvicevaluation";
			data1.lVAFID = vaf01;
		}
		else
		// 1038
		{
			url = rootUrl + "/advicevaluation/sendotheradvice";
			data1.VAF01 = vaf01;
			data1.acf01 = "1";
		}
	}
	else
	{
		$("#yizhujijiaContent").empty();
	}
	$.post(url,data1,function(json)
		{
		debugger;
			var rows = json.rows;
			vbd_jqgrid(rows);
		});

}

var adjust_row1,adjust_col1;
function vbd_jqgrid(data)
{
	for(var i = 0;i<data.length;i++)
	{
		if(data[i].danjia){
			data[i].danjia = data[i].danjia.toFixed(2);
		}
	}
	var tname = yizhujijiaContent;
	$('#jijia_jq_container').resize(function(){
		$("#yizhujijiaContent").setGridWidth($("#jijia_jq_container").width()*1);
	});
	jQuery('#yizhujijiaContent').GridUnload();
	var colModel = [];
	if(valueArr['p_9999_9999_105']=="1")
	{
		colModel = [
		            {label : "项目编码",name : 'bby04'},
			{label : "收费项目",name : 'vaf22',width:"350"},
			{label : "规格",name : 'bby06',align : 'center'},                                        
			{label : "单位",name : 'bby08',align : 'center'},
			{label : "数量",name : 'vaf21',align : 'center'},
			{label : "单价",name : 'danjia',sortable : true,align : 'center'},
			{label : "全价",name : 'danjia',sortable : true,align : 'center',editable : true,edittype : 'text',editoptions: {class: 'form-input'}},
			{label : " ",name : 'adjust',width:"100",cellattr: function(rowId, tv, rawObject, cm, rdata) {return 'id='+tname+'_adjust' + rowId; }},
			{label : "金额",name : 'zongjia',sortable : true,align : 'center'},
			//{label : "执行科室",name : 'bck03',align : 'center'},
			{label : "保险类型",name : 'aas02',align : 'center'},
			{name : 'vaj01',hidden : true},
			{name : 'bby19',hidden : true},
			{name : 'bby20',hidden : true},
			{name : 'bby27',hidden : true},
			{name : 'bby28',hidden : true}
		];
	}
	else
	{
		colModel = [
		            {label : "项目编码",name : 'bby04'},
					{label : "收费项目",name : 'vaf22',width:"350"},
					{label : "规格",name : 'bby06',align : 'center'},                                        
					{label : "单位",name : 'bby08',align : 'center'},
					{label : "数量",name : 'vaf21',align : 'center'},
					{label : "单价",name : 'danjia',sortable : true,align : 'center'},
					{label : "金额",name : 'zongjia',sortable : true,align : 'center'},
					//{label : "执行科室",name : 'bck03',align : 'center'},
					{label : "保险类型",name : 'aas02',align : 'center'},
					{name : 'vaj01',hidden : true},
					{name : 'bby19',hidden : true},
					{name : 'bby20',hidden : true},
					{name : 'bby27',hidden : true},
					{name : 'bby28',hidden : true}
				];
	}
	jQuery("#yizhujijiaContent").jqGrid(
			{
			data:data,
			datatype : "local",
			colModel :colModel,
			sortname : 'vaj38',
			viewrecords : true,
			rowNum : 1000,
			height : 'auto',
			width : '100%',
			autowidth : true,
			forceFit:true,
		    shrinkToFit:true,
			rownumbers : true,
			footerrow:true, 
			sortorder : "desc",
//			cellEdit : true,
			beforeEditCell : function(rowid, cellname, value, iRow, iCol)
			{
				adjust_row1 = iRow;
				adjust_col1 = iCol;
			},
			afterSaveCell : function(rowid,celname,value,iRow,iCol) {
				debugger;
				var rowData = $("#yizhujijiaContent").jqGrid("getRowData", rowid);
				var newvaj38 = Number(rowData.danjia)*Number(rowData.vaf21);
				jQuery("#yizhujijiaContent").setCell(adjust_row1, adjust_col1+2, newvaj38);
				jQuery("#yizhujijiaContent").setCell(adjust_row1, adjust_col1-1, rowData.danjia);
			},
			loadComplete : function(data)
			{
				//判断医嘱发送状态，进行调价编辑
				if(data.rows){
					for(var i =0;i<data.rows.length;i++){
						if(data.rows[i].vaf10 == 8 && data.rows[i].bby19 == 1){
							
							$('#yizhujijiaContent').setGridParam({cellEdit:true,cellsubmit:'clientArray'}).trigger("reloadGrid");
							var ids = jQuery("#yizhujijiaContent").jqGrid('getDataIDs');
							for (var i = 0; i < ids.length; i++)
							{
								var cl = ids[i];
								var copyInput = "<button class='btn btn-min btn-white' onclick='adjustThisPrice(this)' >确定</button>";
								jQuery("#yizhujijiaContent").jqGrid('setRowData', ids[i],
										{
									 adjust : copyInput
										});
							}
						}
					}
				}
				var rowNum=parseInt($(this).getGridParam("records"),10);  
				 if(rowNum>0){               
        	    	 $("#yizhujijiaContent .ui-jqgrid-sdiv").show();                
        	    	 var sum=$(this).getCol("zongjia",false,"sum").toFixed(2);  
        	    	 $(this).footerData("set",{"projname":"合计","zongjia":sum});                               //将合计值显示出来           
        	    	 $(this).footerData("set",{"projname":"合计","vaf22":"合计"});                               //将合计值显示出来           
		   	     }else{                
		   	    		 $("#yizhujijiaContent .ui-jqgrid-sdiv").hide(); 
		   	    		var $tr = $('#yizhujijiaContent').find('tbody>tr:last');
						var len = $tr.find('td').length;
						$("#yizhujijiaContent").html('<tr><td colspan="'+ parseInt(len)+ '" style="text-align:left;">该医嘱暂无计价信息！</td></tr>');
		   	    }
			}
			});
}

/**
 * 费用变价
 * @param that
 */
function adjustThisPrice(that)
{
	$(that).attr("disabled",true);
	jQuery('#yizhujijiaContent').jqGrid("saveCell", adjust_row1, adjust_col1);
	jQuery('#yizhujijiaContent').jqGrid("restoreCell", adjust_row1, adjust_col1);
	var rowid = $(that).parents("tr").attr("id");
	var rowData = $("#yizhujijiaContent").jqGrid("getRowData", rowid);
	var curPrice = rowData.danjia;
//	var newvaj38 = Number(curPrice) * Number(rowData.vaf21);
//	jQuery("#yizhujijiaContent").setCell(adjust_row1, adjust_col1+2, newvaj38);
//	jQuery("#yizhujijiaContent").setCell(adjust_row1, adjust_col1-1, curPrice);
//	var rowData1 = $("#yizhujijiaContent").jqGrid("getRowData", rowid);
	var param = {};
	var arr= [];
	arr.push(rowData);
	param.vaj1List = arr;
	if(Number(curPrice) > Number(rowData.bby27?rowData.bby27:0) && Number(curPrice) < Number(rowData.bby28?rowData.bby28:100))
	{
		var url = rootUrl +"/clidoctor/updateVaj1";
		var para = {params: JSON.stringify(param)};
		$.when($.post(url, para)).done(function(data) 
		{
			if(data && data.result=="Failure" && data.resultMsg=="jiezhang")
			{
				layer.msg('项目已经结账，不能再变价！',{time:3000,icon:2,skin: 'layui-layer-msg2'});
			}
			 $(that).removeAttr("disabled");
			 debugger;
			 if(dataObjT.fun=="1")
			 {
				 headPrice(dataObjT.cbm01);
			 }
			 else if(dataObjT.fun=="2")
			 {
				 vbdInfo(dataObjT.dataObj);
			 }
		})
	}
	else
	{
		$(that).removeAttr("disabled");
		layer.msg('调价范围为'+(rowData.bby27?rowData.bby27:0)+' ~ '+(rowData.bby28?rowData.bby28:100)+'请重新填写',{icon : 1,skin: 'layui-layer-msg1',shade :[0.1, '#393D49'],time : 4000});
	}
}
// 编辑医嘱信息（传编辑的标志参数，根据参数判断赋值）
function editAdivce(that)
{
	debugger;
	$(that).attr("disabled",true);
	var isoperate = isOperateAdvice();
	if(!isoperate){
		layer.msg("该病人已经过了开嘱期限，请重新挂号！",{ time: 3000,icon: 0,skin: 'layui-layer-msg0'});
		return false;
	}
	var checkedAdivce = $(".innerHead td input:checked");
	if (checkedAdivce.length < 1)
	{
		layer.msg("请选择要编辑的医嘱！",
		{
		time : 3000,
		icon : 0,
		skin: 'layui-layer-msg0'
		});
	}
	else if (checkedAdivce.length > 1)
	{
		layer.msg("只能选择一个医嘱单信息进行编辑！",
		{
		time : 3000,
		icon : 0,
		skin: 'layui-layer-msg0'
		});
	}
	else if (checkedAdivce.length == 1)
	{
		var dataStr = $($(checkedAdivce).parents("tbody").find(".yizhu_details")[0]).attr("data-info");
		var dataObj = JSON.parse(dataStr);
		var vaf10 = dataObj.vaf10;
		var cbm01 = dataObj.cbm01;
		if(vaf10 == '8'){
    		$.when(
    				adviceBackToNew(cbm01)
    		).done(function (data) {
    			debugger;
    			if(data){ //证明回退成功
    				showEditPage(cbm01);
    			}
    		});
    	}else if(vaf10 == '1'){
    		showEditPage(cbm01);
    	}
    	else{
    		layer.msg('非新开状态的医嘱不允许编辑',{time : 4000,icon : 2,skin: 'layui-layer-msg2'});
    	}
		
		
	}
	$(that).removeAttr("disabled");

}
//医嘱打开编辑页面
function showEditPage(cbm01){
	var vaa01 = $("#vaa01").val();
	var vac01 = $("#vac01").val();
	var vaa05 = $("#vaa05").text();
	var age = $("#age").text();
	var kaidankeshi = $("#departmentList").find("option:selected").attr("id");
	layer.open(
			{
			type : 2,
			title : '编辑医嘱  ' + vaa05 + "  " + age,
			area : [
			"95%", "95%"
			],
			shade : 0.3,
			maxmin : true,
			content : myurl + "/neworder.jsp?vaa01=" + vaa01 + "&vac01=" + vac01 + "&bck01=" + bck01+"&cbm01="+cbm01+"&kaidankeshi="+kaidankeshi+ "&isEdit=true",
			success : function(index)
			{
			},
			cancel: function(index){ 
				layer.close(index);
				closeAndRefresh_parent();
			}
			});
}
//医嘱回退
function adviceBackToNew(cbm01){
	var vak01s="";
	var def = $.Deferred();
	var htFlag= true;
	var dl1 =$("#date1_p").val();
	var dl2 =$("#dl2").val();
	var arr = getVak01s();
	if(arr.length>0){
		vak01s = arr.join(",");
	}
	$.ajax({
		url : rootUrl + "/clideladvice/backAdvice",
		type : "post",
		data :
		{
		"cbm01" : "{"+cbm01+"}",
		"bce03" : bce03,
		"lbce01" : bce01,
		"date1" : dl1,
		"date2" : dl2,
		"vak01s" : vak01s,
		"lmember" : 2
		},
		dataType: "json",
		success: function (data) {
			if (data.result != "Success")
			{
				layer.alert(data.resultMsg,
				{
				icon : 2,
				});
				htFlag = false;
			}
			def.resolve(htFlag);
		}
	});
	return def.promise();
}
/**
 * 关闭并刷新parent
 */
function closeAndRefresh_parent()
{
	var tableId = "";
	if($(window.parent.document).find("#myPatientTab").hasClass("active"))
	{
		tableId = "myjiezhenTableList";
	}
	else
	{
		tableId = "jiezhenBenkeTable";
	}
	var rowid = $(window.parent.document).find("#"+tableId).jqGrid("getGridParam", "selrow");
	$(window.parent.document).find("#"+tableId).setSelection(rowid);
//	parent.layer.close(parent.layer.getFrameIndex(window.name));// 关闭弹出层
}


// 医嘱操作-----删除
function deleteAdivce()
{
	$("#sc").attr("disabled",true);
	var isoperate = isOperateAdvice();
	if(!isoperate){
		layer.msg("该病人已经过了开嘱期限，请重新挂号！",{ time: 4000,icon: 0,skin: 'layui-layer-msg0'});
		return false;
	}
	var vaf01s = "",vak01s="";
	var cbm01s = "";
	var flag = false;
	var arr = $(".innerHead td input:checked");
	if (arr.length){
		layer.confirm('确定要删除所选项', 
		{
			cancel:function(){
				$("#sc").removeAttr("disabled");
			},
			btn : ['确定', '取消'],
			icon:3,// 按钮
		}, function()
		{
			$(".innerHead td input:checked").each(function(){ // 遍历选中的checkbox
				$(this).parents("tbody").find(".yizhu_details").each(function(i, e)
				{
					var dataStr = $(e).attr("data-info");
					var dataObj = JSON.parse(dataStr);
					var vaf01 = dataObj.vaf01;
					cbm01 = dataObj.cbm01;
					if (dataObj.vaf10 == "1")
					{
						vaf01s += vaf01 + ",";
						flag = true;
					}
					else if (dataObj.vaf10 == "8")
					{
						flag = true;
						vaf01s += vaf01 + ",";
						cbm01s += cbm01+",";
					}
					if(bce03 != (dataObj.bce03g?dataObj.bce03g:dataObj.bce03a))
					{
						layer.msg('不能删除其他医生开的医嘱',
								{
							time : 3000,
							icon : 1,
							skin: 'layui-layer-msg1'
							});
						$("#sc").removeAttr("disabled");
						return false;
					}
				});
			});
//			$(".innerHead td input:checked").each(function()
//			{ // 遍历选中的checkbox
//				$(this).parents("tbody").find(".yizhu_details").each(function(i, e)
//				{
//					var dataStr = $(e).attr("data-info");
//					var dataObj = JSON.parse(dataStr);
//					var vaf01 = dataObj.vaf01;
//					cbm01 = dataObj.cbm01;
//					if (dataObj.vaf10 == "1")
//					{
//						vaf01s += vaf01 + ",";
//						flag = true;
//					}
//					else if (dataObj.vaf10 == "8")
//					{
//						flag = true;
//						vaf01s += vaf01 + ",";
//						cbm01s += cbm01+",";
//					}
//				});
//			});
			var dl1 =$("#date1_p").val();
			var dl2 =$("#dl2").val();
			var arr = getVak01s();
			if(arr.length>0){
				vak01s = arr.join(",");
			}
				
			if (flag)
			{
				cbm01s = cbm01s.substring(0, cbm01s.length - 1);
				vaf01s = vaf01s.substring(0, vaf01s.length - 1);
				var url = rootUrl + "/clideladvice/removeAdvice1";
				var data =
				{
					"cbm01" : "{"+cbm01+"}",
					"lbce01" : bce01,
					"date1" : dl1,
					"date2" : dl2,
					"vak01s" : vak01s,
					"lmember" : 2,
					"vaf01s" : vaf01s,
					"bce03" : bce03
				};
				var callback = function(data, status)
				{
					if (data.result == "Success")
					{
						layer.msg('删除成功',
						{
						time : 2000,
						icon : 1,
						skin: 'layui-layer-msg1'
						});
						$("#sc").removeAttr("disabled",true);
						patientDoctorAdvice($("#vac01").val(), curr);
					}
					else
					{
						layer.alert('数据异常请联系管理员！',
						{
						icon : 2,
						});
						$("#sc").removeAttr("disabled",true);
					}
				};
				$.post(url, data, callback);
			}
			else
			{
				layer.msg('包含已结账或者不允许删除的医嘱，请检查',
				{
				time : 4000,
				icon : 0,
				skin: 'layui-layer-msg0'
				});
				$("#sc").removeAttr("disabled",true);
			}

		}, function()
		{
			$("#sc").removeAttr("disabled");
		});
	}
	else
	{
		layer.msg('请选择要删除的处方',
		{
		time : 3000,
		icon : 0,
		skin: 'layui-layer-msg0'
		});
		$("#sc").removeAttr("disabled",true);
	}
	// })
}

// 医嘱退费--作废
var indexvby1;
function vby1()
{
	$("#zf").attr("disabled",true);
	debugger;
	var cloneArr = [] ;
	var cbm01;
	var vaf10;
	var cbm01list;
	var flag;
	var count = 0;
	var vby1arr = $(".innerHead td input:checked");//要作废的医嘱单
	if(vby1arr.length > 0 ){
		var isBenren = false;
		$(".innerHead td input:checked").each(function()
				{ // 遍历选中的checkbox
					$(this).parents("tbody").find(".yizhu_details").each(function(i, e)
					{
						var dataStr = $(e).attr("data-info");
						var dataObj = JSON.parse(dataStr);
						if(bce03 != (dataObj.bce03g?dataObj.bce03g:dataObj.bce03a))
						{
							isBenren = true;
							
						}
					});
				});
		if(isBenren){
			layer.alert('不能作废其他医生开的医嘱',
				{
				icon : 0,
				});
			$("#zf").removeAttr("disabled");
			return false;
		}
		$(".innerHead td input:checked").each(function()
				{ // 遍历选中的checkbox
					count++;
					flag = false;
					cbm01list = $(this).parents("tr").attr("data-cbm01List");
					$(this).parents("tbody").find(".yizhu_details").each(function(i, e)
					{
						var dataStr = $(e).attr("data-info");
						var dataObj = JSON.parse(dataStr);
						var vaf01 = dataObj.vaf01;
						cbm01 = dataObj.cbm01;
						vaf10 = dataObj.vaf10;
						if(vaf10=='8')
						{
							flag = true;
						}
						cloneArr.push(dataObj);
					})
					if(!flag)
				{
					layer.alert("存在不能作废的医嘱，请重新选择！",{icon:0,title:'提示'});
					$("#zf").removeAttr("disabled");
					return false;
				}

				});
				if(flag){
						laytplUrl(myurl + "/module/advice_vby1_table.html",{}, function(data, html) {
							indexvby1 = layer.open({
								type : 1,
								// scrollbar : false,
								title : "医嘱作废",
								area : [ "80%", "80%" ],
								shade : 0.1,
								maxmin : true,
								content : html,
								closeBtn : 1,
								success : function() {
									$("#zf").removeAttr("disabled");
									//加载jqgrid 表格数据
									loadVby1Jqgrid(cloneArr);
									$("#vby1_cancel").on("click",function(){
										layer.close(indexvby1);
									});
								}
							})
							
						});
				}
	}else{
		layer.msg("请选择要作废的医嘱单",
				{
			time : 3000,
			icon : 0,
			skin: 'layui-layer-msg0'
				});
		$("#zf").removeAttr("disabled");
		return;
	}

}
//医嘱退费弹出框确认按钮
function makeSureVby1(){
	debugger;
	var table_id = "adviece_table_vby1";
	jQuery('#'+table_id).jqGrid("saveCell", adjust_row1, adjust_col1);
	jQuery('#'+table_id).jqGrid("restoreCell",adjust_row1, adjust_col1);
	var vaf01s = "";
	var dataarr = new Array();
	var selectedIds = $("#adviece_table_vby1").jqGrid("getGridParam", "selarrrow");
	if (selectedIds.length)
	{
		for (var i = 0; i < selectedIds.length; i++)
		{
			debugger;
			var data = $("#adviece_table_vby1").jqGrid("getRowData", selectedIds[i]);
			if(parseFloat(data.vaf21) > parseFloat(data.vaf21_s)){
				var anthority_cur = $('#'+table_id).find("#"+selectedIds[i]).find("td[aria-describedby='"+table_id+"_vaf21']");
				layer.tips('总量不能大于处方总量('+data.vaf21_s+')！', anthority_cur,{ tips: [1] });
				return false;
			}
			dataarr.push(data);
			vaf01s += data.vaf01 + ",";
		}
		vaf01s = vaf01s.substring(0, vaf01s.length - 1);
		layer.confirm("确定作废所选项？", 
		{
			btn : [
			'确定', '取消'
			],
			icon:3,
		// 按钮
		}, function()
		{
			layer.msg('作废中....', {icon: 16,shade: [0.1, '#393D49'],time:0,skin: 'layui-layer-msg16'}); 
			var url = rootUrl + "/clideladvice/vby1";
			var data =
			{
			"vaf01s" : JSON.stringify(dataarr),
			"bce03" : bce03,
			"lbce01" : bce01,
			"lmember" : 2
			};
			$.ajax({
				url : url,
				type : "post",
				data : data,
				async : false,
				dataType : 'json',
				success : function(data)
				{
					layer.alert(data.resultMsg,
						{
						icon : 0,
						});
						patientDoctorAdvice($("#vac01").val(), curr);
						layer.close(indexvby1);
					
				}
		});
		}, function()
		{

		});
	}else{
		layer.msg("请选择要作废的处方！",
				{
				time : 3000,
				icon : 0,
				skin: 'layui-layer-msg0'
				});
	}

}
//医嘱作废Jqgrid表格加载(2017-10-18改为可编辑数量)
function loadVby1Jqgrid(cloneArr){
	var tname = "adviece_table_vby1";
	$("#adviece_table_vby1").GridUnload();
	jQuery("#adviece_table_vby1").jqGrid(
	{
	data : cloneArr,
	datatype : "local",
	height : 'auto',
	width : 'auto',
	autowidth : true,
	autoheight : true,
	multiselect : true,
	colModel : [
	{
	name : 'bbx01',
	hidden : true,
	},
	{
	name : 'bby01',
	hidden : true,
	},
	{
	name : 'vaf01',
	hidden : true,
	},
	{
		label : '药品类型',
	name : 'cbm01',
	hidden : true,
//	formatter: function (cellvalue, options, rowObject) {
//		debugger;
//		if(rowObject.bda01){
//			var result;
//			switch (rowObject.bda01) {
//				case "1": result = "西成药"; break;
//				case "2": result = "西成药"; break;
//				case "8": result = "中草药"; break;
//				case "E": result = "检查"; break;
//				case "L": result = "检验"; break;
//				case "S": result = "手术"; break;
//			}
//			return result;
//			
//		}
//    }
	},
	{
	label : '状态',
	name : 'fstatus',
	//align : "left",
	},
	{
	label : '时间',
	name : 'vaf36',
//	align : "center",
	},
	{
	label : '医嘱内容',
	name : 'vaf22n',
//	align : "left",
	width: '250px'
	},
	{label : "总量",name : 'vaf21',align : 'center',editable : true,edittype : 'text'},
	{
		
		name : 'vaf21_s',
	    hidden:true
	},
	{
		
		name : 'vaf21tf',
		hidden:true
	},
	{
	label : '用法',
	name : 'fusage',
//	align : "right",
	},
	{
	label : '医生嘱托',
	name : 'vaf23',
//	align : "right",
	},
	{
	label : '开嘱医师',
	name : 'bce03g',
//	align : "right",
	},
	{
	label : '执行科室',
	name : 'nbck03',
//	align : "right",
	},
	{
	label : '附加执行',
	name : 'bck03f',
//	align : "right",
	},
	{
	label : '执行性质',
	name : 'vaf58',
//	align : "right",
	},
	],
	grouping : true,
	groupingView :
	{
//	groupSummary : [true],
	groupField :['cbm01'],
	groupColumnShow :[false],
//	groupText :['<label class="label-normal label-spring">{0}</label>']
	groupText: ['<label class="label-normal label-spring"><input type="checkbox" class="check-group-by-name magic-checkbox"  onclick="checkGroup(this,\''+tname+'\',\'{0}\')"/><span>{0} - {1}条</span></label>'],   // 表头显示的数据以及相应的数据量
   
	},
	beforeEditCell : function(rowid, cellname, value, iRow, iCol)
	{
		adjust_row1 = iRow;
		adjust_col1 = iCol;
	},
	afterSaveCell : function(rowid,celname,value,iRow,iCol) {
		debugger;
		var rowData = $('#'+tname).jqGrid("getRowData", rowid);
		var anthority_cur =$('#'+tname).find("#"+rowid).find("td:eq("+iCol+")");
		jQuery('#'+tname).setCell(rowid, "vaf21tf", rowData.vaf21);
		var authority_val = anthority_cur.text();
		if(celname == "vaf21" ){
			if(parseFloat(authority_val) > parseFloat(rowData.vaf21_s)){
				layer.tips('总量不能大于处方总量('+rowData.vaf21+')！', anthority_cur,{ tips: [1] });
			}
			
		}
	},
	ondblClickRow : function(rowid, status)
	{
	},
	onSelectAll : function(aRowids,status){
        if(status){
            $('#'+tname+' .check-group-by-name').prop('checked',true);
        }else{
            $('#'+tname+' .check-group-by-name').prop('checked',false);
        }
    },
	onSelectRow : function(rowid,status)
	{
		 var row = $("#adviece_table_vby1").jqGrid("getRowData", rowid);
		 if(!status){
                var groupTr = $('#'+tname+' tr#'+rowid).prevAll('.jqgroup')[0];
                $(groupTr).find('[type="checkbox"]').prop('checked',false);
            };
	},
	loadComplete : function(data)
	{
		debugger;
		$('#'+tname).setGridParam({cellEdit:true,cellsubmit:'clientArray'}).trigger("reloadGrid"); //设置编辑
		var ids = jQuery("#adviece_table_vby1").jqGrid('getDataIDs');
		for (var i = 0; i < ids.length; i++)
		{
			var rowData = $("#adviece_table_vby1").jqGrid("getRowData", ids[i]);
			jQuery('#'+tname).setCell(ids[i], "vaf21_s", rowData.vaf21);
			jQuery('#'+tname).setCell(ids[i], "vaf21tf", rowData.vaf21);
		}
		
	}
	});

}

//checkbox选中框
function checkGroup(obj,tname,pname){
    var dd =  $('#'+tname).jqGrid("getDataIDs");
    var groupArr = [];
    for(var i=0;i<dd.length;i++){
        var row =  $('#'+tname).jqGrid("getRowData", dd[i]);
        if(row.cbm01==pname){
            groupArr.push(dd[i]);
        }
    };
    var thisGroup_checked = $(obj).prop('checked');
    for(var j= 0,jLen = groupArr.length;j<jLen;j++){
        var thisRow_checked = $('#jqg_'+tname+'_'+groupArr[j]).prop('checked');
        if(thisRow_checked&&thisGroup_checked){
            continue;
        }
        else{
            $('#'+tname).jqGrid('setSelection',groupArr[j]);
        }
    }
}
// 弹出首页界面
function shouye()
{
	var vaa01 = $("#vac01").val();
	if (typeof (vaa01) != "undefined" && vaa01 != "")
	{
		jibenxinxi();
		guomin();
		shouye12();
		shouye13();
		$("#shouye").modal("show");
	}
	else
	{
		alert("请选择病人信息！");
	}
}

// //医嘱回退
function backAdvice()
{
	var cbm01;
	var vaf10;
	$('input:checkbox[name=advice]:checked').each(function(i)
	{
		cbm01 = $(this).parent().parent().children().find("input[name='cbm01']").val();
		vaf10 = $(this).parent().parent().children().find("input[name='vaf10']").val();
	});
	if (typeof (cbm01) == undefined)
	{
		alert("请选择要回退的医嘱单");
		return;
	}
	else if (vaf10 == "1")
	{
		alert("没有需要回退的医嘱单");
		return;
	}
	else
	{
		alert("cbm01=" + cbm01 + " 确定回退？");
		var url = rootUrl + "/cloud/clideladvice/backAdvice";
		var data =
		{
		"cbm01" : "{"+cbm01+"}",
		"bce03" : bce03,
		"lbce01" : bce01,
		"lmember" : 2
		};
		var callback = function(data, status)
		{
			alert(data.resultMsg);
		};
		$.post(url, data, callback);
	}
}

function print_content()
{
	var datastr = $("#advice_print option:selected").attr("data-info");
	if(datastr){
		var dataObj = JSON.parse(datastr);
		var id = dataObj.id;
		var vaf10 = dataObj.vaf10;
		if(vaf10 == '8'){
			var url = printUrl+"/printtoolrest/printToPdf/"+id+"?cbm01="+cbm01;
	    	layer.closeAll();         // 打印前先关闭已经打开 layer 弹框
	        layer.open({
	            type: 2,
	            title:false,          // title 不显示
	            closeBtn: 0,          // 不显示  layer 弹框关闭按钮
	            shadeClose: false,
	            shade: false,
	            area: ['0%', '0%'],   //在页面上不显示
	            content: url,         //iframe的url,
	            success:function(){
	                $(".print_btn").removeAttr("disabled");
	            }
	        });
		}else{
			if(vaf10 == '1'){
				layer.msg("请先发送医嘱单！",{time:3000,icon:0,skin: 'layui-layer-msg0'});
			}else if(vaf10 == '4'){
				layer.msg("医嘱已作废，请重开！",{time:3000,icon:0,skin: 'layui-layer-msg0'});
			}
			$(".print_btn").removeAttr("disabled");
		}
	}else{
		layer.msg("请选择打印的医嘱单！",{time:3000,icon:0,skin: 'layui-layer-msg0'});
		$(".print_btn").removeAttr("disabled");
	}
	
}
var zhenjin_index;
/**
 * 选择诊查费
 */
var care_zj_edit_row;
var care_zj_edit_col;
function zhenjin1()
{
	$.ajax({
		url:rootUrl+"/clidoctor/queryHasZj",
		type:"get",
		dataType:"json",
		data:{vac01:$("#vac01").val(),hours:valueArr['p_9999_9999_95']},
		async:false,
		success:function(data)
		{
			var flag = data.map.flag;
			if(flag)
			{
//				sendFlag = false;
				//查询诊查费列表
				var zjList;
				$.ajax({url:rootUrl+"/clidoctor/queryZjList",type:"get",async:false,dataType:"json",success:function(data){
					zjList = data.list;
				}});
				laytplUrl(myurl + "/module/zhenjin.html",{}, function(data, html) {
					zhenjin_index = layer.open({
						type : 1,
						// scrollbar : false,
						title : "选择诊查费",
						area : [ "500px", "500px"],
						shade : 0.1,
						maxmin : true,
						content : html,
						closeBtn : 1,
						cancel:function(){
							$("#fasong").removeAttr("disabled");
							layer.msg("医嘱发送已取消！",{time : 3000,
								icon : 0,
								skin : 'layui-layer-msg0'});
//							sendFlag = true;
//							var zjAddList = [];
//							sendZj(zjAddList);
						},
						success : function() {
							$("#zhenjin_table").empty();
							$("#zhenjin_table").GridUnload();
							jQuery("#zhenjin_table").jqGrid(
									{
										data : zjList,
										datatype : "local",
										height : 'auto',
										width : 'auto',
										autowidth : true,
										autoheight : true,
										multiselect : true,
										multiboxonly:true,
										colModel : [
										            {
										            	label:'项目名称',
										            	name : 'bby05',
										            	align : 'left',
										            	width:'400'
										            },
										            {
										            	name : 'bdn01',
										            	hidden : true
										            },
										            {
										            	name : 'bby01',
										            	hidden : true
										            },
										            {
										            	label : '数量',
										            	name : 'amount',
										            	align : "right",
//										            	editable : true,
//										            	edittype : 'text',
										            	formatter : function(value, options, rData){
										       		    	if(value){
										       		    		 val =value;
										       		    	   }else{
										       		    		 val=1;
										       		    	   }
										       		    	return val;
										       		    	}
										            },
										            {
										            	label : '单价',
										            	name : 'bby25',
										            	align : "right"
										            },
										            {
										            	label : '金额',
										            	name : 'bby25',
										            	align : "right"
										            }
										            ],
//										            cellEdit : true,
//													cellsubmit : "clientArray", // 表示在本地进行修改
													beforeEditCell : function(rowid, cellname, value, iRow, iCol)
													{
														debugger;
														care_zj_edit_row = iRow;
														care_zj_edit_col = iCol;
													},
										            ondblClickRow : function(rowid, status)
										            {
										            	var row = $("#zhenjin_table").jqGrid("getRowData", rowid);
										            }
									});
							$("#zhenjin_cancle").on("click",function(){
								//这里添加弹出提示：是否不添加诊金
								layer.close(zhenjin_index);
								$("#fasong").removeAttr("disabled");
								layer.msg("医嘱发送已取消！",{time : 3000,
									icon : 0,
									skin : 'layui-layer-msg0'});
//								sendFlag = true;
//								var zjAddList = [];
//								sendZj(zjAddList);
							});
							//获取诊金数据
							addZhenji1();
						}
					})

				});
			}
			else
			{
				var zjAddList = [];
				sendZj(zjAddList);
			}
		}
	});
}

/**
 * 保存诊金费用1
 */
function addZhenji1()
{
	var zjAddList = [];
	$("#add_zhenji").on("click",function(){
		debugger;
		$('#zhenjin_table').jqGrid("saveCell", care_zj_edit_row, care_zj_edit_col);
		$('#zhenjin_table').jqGrid("restoreCell", care_zj_edit_row, care_zj_edit_col);
		var ids = $('#zhenjin_table').jqGrid('getGridParam','selarrrow');
		for (var int = 0; int < ids.length; int++)
		{
			zjAddList.push($("#zhenjin_table").jqGrid("getRowData", ids[int]));
		}
		layer.close(zhenjin_index);
		sendZj(zjAddList);
	});
}

